import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { CustomerDuplicateEntity } from '../../entity/duplicate';
import { CustomerDuplicateService } from '../../service/duplicate';
import { CustomerCustomerEntity } from '../../entity/customer';
import { BaseSysUserEntity } from '../../../base/entity/sys/user';

/**
 * 客户查重
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: CustomerDuplicateEntity,
  service: CustomerDuplicateService,
  pageQueryOp: {
    fieldEq: ['a.status'],
    join: [
      {
        entity: CustomerCustomerEntity,
        alias: 'b',
        condition: 'a.duplicateCustomerId = b.id',
        type: 'leftJoin',
      },
      {
        entity: BaseSysUserEntity,
        alias: 'c',
        condition: 'a.userId = c.id',
        type: 'leftJoin',
      },
    ],
    select: [
      'a.*',
      'b.name as duplicateName',
      'b.phone as duplicatePhone',
      'c.nickName as userName',
    ],
  },
})
export class AdminCustomerDuplicateController extends BaseController {
  @Inject()
  customerDuplicateService: CustomerDuplicateService;
}
